<template>
  <div class="lawyer-info">
    <div class="bg-c-fff">
      <h2 class="box-title rel">个人信息管理</h2>
      <form @submit.prevent="onSubmitBtn">
        <ul>
          <li>
            <span>律师姓名：</span>
            <p class="dib p">{{lawyerName}}</p>
          </li>
          <li>
            <span>所属律所：</span>
            <p class="dib p">{{lawfirmName}}</p>
          </li>
          <li>
            <span>律师个人信息：</span>
            <input type="button" value="选择文件" class="upload-css" id="personal">
            <input type="button" value="上传" class="upload-css" @click="startUpload">
            <div class="dib remark">支持.jpg、.jpeg、.gif、.png图片格式，大小不超过5M</div>
            <div class="preview-box">
              <div class="preview" v-if="lawyerInfoUrl===''">
                <div class="db auto tc">待上传</div>
              </div>
              <div class="preview-img" v-else>
                <img :src="lawyerInfoUrl">
              </div>
            </div>
          </li>
          <li>
            <span>律师年检信息：</span>
            <input type="button" value="选择文件" class="upload-css" id="yearly">
            <input type="button" value="上传" class="upload-css" @click="startUploads">
            <div class="dib remark">支持.jpg、.jpeg、.gif、.png图片格式，大小不超过5M</div>
            <div class="preview-box">
              <div class="preview" v-if="lawyerYearUrl===''">
                <div class="db auto tc">待上传</div>
              </div>
              <div class="preview-img" v-else>
                <img :src="lawyerYearUrl">
              </div>
            </div>
          </li>
          <li class="button">
            <span></span>
            <button type="submit" class="blue-button">保存</button>
            <button type="button" class="white-button" @click="cancel">取消</button>
          </li>
        </ul>
      </form>
    </div>
  </div>
</template>
<script type="text/javascript ">
import UploaderManager from '../components/UploaderManager'
export default {
  components: {
    UploaderManager
  },
  data() {
    return {
      uploaderPersonal: '',
      uploaderYearly: '',
      lawyerInfoUrl: '',
      lawyerYearUrl: ''
    }
  },
  mounted() {
    this.initUploader()
    this.onGetaData()
  },
  methods: {
    onSubmitBtn() {
      this.$http.post('/memberLawyer/apply/lawyer/yearInspection', {
          lawyerInfoPic: this.lawyerInfoUrl,
          lawyerYearPic: this.lawyerYearUrl
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('保存成功！')
          this.$router.push('/welcome')
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(() => {
        this.$toasted.show('网络错误')
      })
    },
    onGetaData() {
      this.$http.get('/memberLawyer/query/lawyerInfo').then(data => {
        if (data.data.httpCode === 200) {
          this.lawyerInfoUrl = data.data.data.lawyerInfoPic
          this.lawyerYearUrl = data.data.data.lawyerYearPic
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络错误')
      })
    },
    startUpload() {
      if (this.uploaderPersonal.startUpload()) {

      } else {
        this.$toasted.show('正在上传文件，请稍后再试')
      }
    },
    startUploads() {
      if (this.uploaderYearly.startUpload()) {

      } else {
        this.$toasted.show('正在上传文件，请稍后再试')
      }
    },
    initUploader() {
      this.uploaderPersonal = new UploaderManager('lawyer-photo', 'personal', (url) => { 
        this.lawyerInfoUrl = url
        this.$toasted.show('上传成功')
      }, (msg) => {
        this.$toasted.show(msg)
      })
      this.uploaderYearly = new UploaderManager('lawyerYearly-photo', 'yearly', (url) => {
        this.lawyerYearUrl = url
        this.$toasted.show('上传成功')
      }, (msg) => {
        this.$toasted.show(msg)
      })
    },
    cancel() {
      this.lawyerInfoUrl = ''
      this.lawyerYearUrl = ''
    }
  },
  computed: {
    lawyerName() {
      return this.$store.state.lawyerLoginData.lawyerName
    },
    lawfirmName() {
      return this.$store.state.lawyerLoginData.firmName
    }
  }
}

</script>
<style type="text/css " scoped>
.lawyer-info ul {
  padding-bottom: 70px;
}

.lawyer-info ul li {
  padding: 10px 0;
}

.lawyer-info ul li span {
  width: 194px;
  display: inline-block;
  text-align: right;
  color: #666666;
  margin-right: 20px;
}

select {
  width: 121px;
  height: 35px;
}

.remark {
  width: 403px;
  color: #a5a5a5;
}

.upload-css {
  background-color: #d8e7ff;
  border: 1px solid #2a508c;
  width: 121px;
  height: 40px;
  color: #01378c;
  cursor: pointer;
}

.upload-btn {
  left: -154px;
  top: 0;
  cursor: pointer;
  width: 151px;
}

.icon-asterisk {
  position: relative;
  right: 35px;
  color: #ec5303;
  font-size: 25px;
  top: 3px;
}

.preview-box {
  margin-left: 217px;
  margin-top: 10px;
}

.preview {
  width: 120px;
  height: 120px;
  border: 1px solid #cccccc;
  margin-right: 70px;
}

.input-w1 {
  width: 385px;
}

.p {
  color: #666;
}

.preview div {
  width: 100px;
  height: 100px;
  border-radius: 100%;
  border: 1px solid #cccccc;
  margin-top: 10px;
  line-height: 100px;
  color: #ccc;
}

.preview-img {
  width: 300px;
}

.preview-img img {
  width: 150px;
  height: auto;
}

.button button {
  width: 150px;
  line-height: 35px;
  margin-right: 25px;
}


textarea {
  width: 380px;
  height: 230px;
  padding: 10px 8px;
}

input::-webkit-input-placeholder {
  color: #a5a5a5;
}

</style>
